#!/bin/bash

# 批量修复剩余分页错误的脚本
echo "开始批量修复剩余的分页错误..."

# 需要修复的文件列表（都是缺少pageResult变量定义的问题）
files=(
    "fuint-application/src/main/java/com/fuint/common/service/impl/CommissionRelationServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/BalanceServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/PointServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/BookItemServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/MemberServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/CommissionCashServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/CommissionLogServiceImpl.java"
)

echo "需要修复的文件数量: ${#files[@]}"

# 检查文件是否存在
for file in "${files[@]}"; do
    if [ -f "$file" ]; then
        echo "✓ $file 存在"
    else
        echo "✗ $file 不存在"
    fi
done

echo ""
echo "这些文件都有相同的问题模式："
echo "1. 缺少 Page<EntityType> page = new Page<>(currentPage, pageSize);"
echo "2. 缺少 Page<EntityType> pageResult = mapper.selectPage(page, lambdaQueryWrapper);"
echo "3. 需要添加 PageRequest 和 PageImpl 的正确使用"
echo ""
echo "修复模式："
echo "- 在 lambdaQueryWrapper.orderBy... 之后添加分页变量定义"
echo "- 使用 PageImpl 和 PageRequest 替代直接传递 MyBatis Plus Page"
echo "- 添加类型转换: (int) pageResult.getPages()"
echo ""
echo "请手动修复这些文件，或者继续使用 replace_in_file 工具逐个修复。"
